const express = require("express");
const router = express.Router();
const { MobileCode, loginCode, wechatLogin } = require("../../../api/wechat");
router.post("/login", async (req, res) => {
  wechatLogin(req.body)
    .then((result) => {
      res.send(result);
    })
    .catch((err) => {
      res.send(err);
    });
});
router.post("/getPhoneNumber", (req, res) => {
  let access_token = req.wechat_access_token;
  MobileCode({
    access_token,
    ...req.body,
  })
    .then((phoneResult) => {
      return phoneResult;
    })
    .then((loginResult) => {
      res.send(loginResult);
    })
    .catch((err) => {
      res.send(err);
    });
});
router.post("/wechatCodeLoagin", async (req, res) => {
  loginCode(req.body)
    .then((result) => {
      res.send(result);
    })
    .catch((err) => {
      res.send(err);
    });
});

module.exports = router;
